const fs = require('fs');
const path = require('path');


fs.readFile(path.join(__dirname, 'index.html'), 'utf-8', (err, data) => {
    if (err) return console.log(err);

    css = /<style>([\s\S]*)<\/style>/.exec(data)[1];

    js = /<script>([\s\S]*)<\/script>/.exec(data)[1];

    data = data.replace(/<style>([\s\S]*)<\/style>/, '<link rel="stylesheet" href="index.css" />')
    html = data.replace(/<script>([\s\S]*)<\/script>/, '<script src="index.js"></script>');
    fs.writeFile(path.join(__dirname, 'index', 'index.css'), css, err => {
        if (err) return console.log(err);
        console.log('写入css文件成功')
    });
    fs.writeFile(path.join(__dirname, 'index', 'index.js'), js, err => {
        if (err) return console.log(err);
        console.log('写入js文件成功')
    });
    fs.writeFile(path.join(__dirname, 'index', 'index.html'), html, err => {
        if (err) return console.log(err);
        console.log('写入html文件成功')
    });
})